﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Rocket.Windows.Framework;
using Rocket.Bll.Models;
using Rocket.Core;
using Rocket.Core.Common;

namespace MainForm.ChildControls
{
    public partial class ReaderApplicationData : BaseDataEditor
    {
        private ReaderApplicationQuestionManager readerAppQuestionManager;
        private SummaryDataView sumView = new SummaryDataView();
        public ReaderApplicationData()
        {
            InitializeComponent();
        }

        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
            this.readerApplicationTypeCombo1.LoadData();
        }

        /*protected override void RocketBindingSourceChanged(object sender, EventArgs e)
       {
           //sumView.ReLoad();
       }*/

        public override void SetRocketBindingSource(ref BindingSource raptorBindingSource)
        {
            raptorBindingSource = this.ReaderApplicationViewBindingSource;
        }

        public override V MapIt<V>(int Id, V bindedView)
        {
            BaseObject appView = bindedView;
            appView = bindedView;
            if (Id == 0)
            {
                appView = new ReaderApplicationView();
            }
            appView.Id = Id;
            ((ReaderApplicationView)appView).Code = this.codeTextBox.Text;
            ((ReaderApplicationView)appView).Name = this.nameTextBox.Text;
            ((ReaderApplicationView)appView).AddedDate = this.dateTimePickerUpdatedDate.Value;
            ((ReaderApplicationView)appView).ApplicationType = (ReaderApplicationTypes)DataManager.ConvertToInt(this.readerApplicationTypeCombo1.SelectedValue.ToString());
            return (V)appView;
        }
        ReaderApplicationView BindedView;
        public override void RocketBindingSourceChanged(object sender, EventArgs e)
        {
            BindedView = (ReaderApplicationView)sender;
            this.readerApplicationTypeCombo1.SelectedValue = (int)((ReaderApplicationView)sender).ApplicationTypeId;
            //sumView.RocketBindingSource = 
        }

        private void buttonManageQuestions_Click(object sender, EventArgs e)
        {
            ChildForm<ReaderApplicationView> newForm = new ChildForm<ReaderApplicationView>(BindedView);
            readerAppQuestionManager = new ReaderApplicationQuestionManager(this.BindedView.Code);
            readerAppQuestionManager.Dock = DockStyle.Fill;
            //newForm.StartPosition = FormStartPosition.CenterParent;
            //newForm.Width = 300;
            newForm.Controls.Add(readerAppQuestionManager);
            newForm.ShowDialog();
        }
    }
}
